<template>
	<div class="layout-padding">
		<splitpanes horizontal>
			<pane size='50'>
				<div class="layout-padding-auto layout-padding-view">
					<el-tabs model-value="first">
                        <el-tab-pane name="first">
                            <template #label>
                                <span class="ml-0.5">
                                    {{ $t('fg.FGWarehouseLocation') }}
                                </span>
                            </template>
                        </el-tab-pane>
                    </el-tabs>
				<!--查询条件表单-->
				<el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList">
					<el-form-item :label="$t('fg.locationCode')" prop="locationcode">
						<el-input v-model="state.queryForm.locationcode" clearable :placeholder="$t('fg.printlc')" />
					</el-form-item>

					<el-form-item :label="$t('fg.barcode')" prop="barcode">
						<el-input v-model="state.queryForm.barcode" clearable :placeholder="$t('fg.printbc')" />
					</el-form-item>

					<el-form-item :label="$t('fg.materialCode')" prop="materialcode">
						<el-input v-model="state.queryForm.materialcode" clearable :placeholder="$t('fg.printmc')" />
					</el-form-item>

					<el-form-item>
						<el-button icon="el-icon-search" type="primary"  @click="query">{{ $t('fg.query') }}</el-button>
						<el-button icon="refresh"  @click="resetQuery">{{ $t('fg.reset') }}</el-button>
					</el-form-item>
				</el-form>


                <el-table
					:data="state.dataList"
					highlight-current-row
					v-loading="state.loading"
					border
					style="width: 100%; height: 100%"
					:cell-style="tableStyle.cellStyle"
					@row-click="clickRow"
					stripe
					:header-cell-style="tableStyle.headerCellStyle"
                    @expand-change="handleExpandChange"
				>

                	<!-- 展开行 -->
					<!-- <el-table-column type="expand">
						<template #default="props">
							<detail-list :code="props?.row?.locationCode"></detail-list>
						</template>
					</el-table-column> -->

					<el-table-column type="index" label="#" width="80" />
                    <el-table-column prop="warehouseCode" :label="$t('fg.warehouseCode')" show-overflow-tooltip />
					<el-table-column prop="locationCode" :label="$t('fg.locationCode')" show-overflow-tooltip />
					<el-table-column prop="itemsTotal" :label="$t('fg.itemsTotal')" show-overflow-tooltip >
						<template #default="scope">
                            <!--根据不同的状态选择不同的颜色的tag-->
                            <el-tag  type='primary' effect="plain">
                                {{ scope.row.itemsTotal }}
                            </el-tag>
                        </template>
					</el-table-column>

					<el-table-column prop="materialTotal" :label="$t('fg.materialTotal')" show-overflow-tooltip >
						<template #default="scope">
                            <!--根据不同的状态选择不同的颜色的tag-->
                            <el-tag  type='success' effect="plain">
                                {{ scope.row.materialTotal }}
                            </el-tag>
                        </template>
					</el-table-column>

					<el-table-column prop="maxCapacity" :label="$t('fg.maxCapacity')" show-overflow-tooltip >
						<template #default="scope">
                            <!--根据不同的状态选择不同的颜色的tag-->
                            <el-tag size="large" type='success'>
                                {{ scope.row.maxCapacity }}
                            </el-tag>
                        </template>
					</el-table-column>
					<el-table-column prop="minCapacity" :label="$t('fg.minCapacity')" show-overflow-tooltip >
						<template #default="scope">
                            <!--根据不同的状态选择不同的颜色的tag-->
                            <el-tag size="large" type='danger'>
                                {{ scope.row.minCapacity }}
                            </el-tag>
                        </template>
					</el-table-column>

				</el-table>

				<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
				</div>
			</pane>
			<pane size='50'>
				<div class="layout-padding-auto layout-padding-view">
				<el-tabs model-value="first">
                        <el-tab-pane name="first">
                            <template #label>
                                <span class="ml-0.5">
                                    {{ $t('fg.locationDetail') }}
                                </span>
                            </template>
                        </el-tab-pane>
                    </el-tabs>
					<detailList ref="detailListRef" @refresh="getDataList(false)"/>
				</div>
			</pane>
		</splitpanes>
	</div>
</template>

<script setup lang="ts">
const detailList = defineAsyncComponent(() => import('./detailList.vue'));
import { BasicTableProps, useTable } from '/@/hooks/table';
import { queryLocationDetail } from '/@/api/platform/report/locationdetail';
import { ref, reactive } from 'vue';

const detailListRef = ref()

// 搜索变量
const queryRef = ref();
//表格的配置
const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {},
	pageList: queryLocationDetail,
});

// 点击行的时候触发
const clickRow = (row: any) => {
    detailListRef.value.refresh(row.locationCode)
}

const { tableStyle, getDataList, sizeChangeHandle, currentChangeHandle } = useTable(state);

// 清空搜索条件
function resetQuery() {
// 清空搜索条件
queryRef.value?.resetFields();
	getDataList(false);
	detailListRef.value.refresh("")
}

const query = () => {
    getDataList();
};


</script>